package com.kfm.tool;

public class IpAddressValidator {
    /**
     * 判断ip是否合法
     *
     * @param ip
     * @return
     */
    public static boolean isIpAddress(String ip) {
        String[] ipsplit = ip.split("\\.");
        if (!(ipsplit.length == 4)) {
            return false;
        }
        for (String s : ipsplit) {
            try {
                int number = Integer.parseInt(s);
                if (number < 0 || number > 255) {
                    return false;
                }
            } catch (NumberFormatException e) {
                return false;
            }
        }
        return true;
    }
}
